
/*
 * @项目名称: 模板开发
 * @FilePath: /meek/src/geometry/tiltrectangle.js
 * @Author: zhangning@datatang.com
 * @Date: 2019-11-14T17:59:02+08:00
 * @LastEditors: 447508585@qq.com
 * @LastEditTime: 2023-03-13 18:46:50
 * Copyright (c) 2018-2022 
 */

/**
 * Created by zhangyong on 2017/8/23.
 */

import Geometry from './geometry'
import Polygon from './polygon'
import { distance, deepClone } from './support/geometryutil'

import { getPointInExtendedLineByDistanceFromABOrC, updateTiltRectByRatio, getTwoPointsBytwoPointsAndH, pointDistanceToSegment, getProjectionPointOnLine } from './support/geometryutil'

export default class TiltRectangle extends Polygon {

  constructor(coordinates) {
    super(coordinates)
    /**
     * 记录上一次第三个点坐标
     */
    this._thirdRecordPoint = null
    /** 
     * 记录上一次第4个点坐标
    */
    this._forthRecordPoint = null

    this._oldCoordinates = null
  }


  get geometryType() {
    return Geometry.TILTRECTANGLE
  }

  /**
   * 计算最小外接矩形的宽
   *
   * @property width
   * @returns {Number}
   */
  get width() {
    const coords = this.getCoordinates();
    const p1 = coords[0][1];
    const p2 = coords[0][2]
    const dx = Math.abs(p1[0] - p2[0]);
    const dy = Math.abs(p1[1] - p2[1]);
    var dis = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
    return dis;

  }

  /**
   * 计算最小外接矩形的高
   *
   * @property height
   * @returns {Number}
   */
  get height() {
    const coords = this.getCoordinates();
    const p1 = coords[0][0];
    const p2 = coords[0][1]
    const dx = Math.abs(p1[0] - p2[0]);
    const dy = Math.abs(p1[1] - p2[1]);
    var dis = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
    return dis;
  }

  /**
   * 移动矩形通过x，y值
   *
   * @method move
   * @param x {Number}
   * @param y {Number}
   */
  move(x = 0, y = 0, opts) {
    let beyond
    if (opts) {
      if (opts.beyond) {
        beyond = opts.beyond
      }
    }

    const oldCoordinates = this.getCoordinates();
    const p0 = oldCoordinates[0][0];
    const p1 = oldCoordinates[0][1];
    const p2 = oldCoordinates[0][2];
    const p3 = oldCoordinates[0][3];
    const p4 = oldCoordinates[0][4];

    let newCoordiante = [[
      [p0[0] + x, p0[1] + y],
      [p1[0] + x, p1[1] + y],
      [p2[0] + x, p2[1] + y],
      [p3[0] + x, p3[1] + y],
      [p4[0] + x, p4[1] + y],
    ]]

    if (!beyond) {
      this.setCoordinates(newCoordiante);
      return;
    }

    let xMin = beyond.xmax
    let yMin = beyond.ymax
    let xMax = 0
    let yMax = 0
    for ( let p of newCoordiante[0] ) {
      if ( p[0] < xMin ) {
        xMin = p[0]
      } else if ( p[0] > xMax ) {
        xMax = p[0]
      }

      if ( p[1] < yMin ) {
        yMin = p[1]
      } else if ( p[1] > yMax ) {
        yMax = p[1]
      }
    }

    if ( xMax > beyond.xmax ) {
      x = x - ( xMax - beyond.xmax );
    } else if ( xMin < beyond.xmin ) {
      x = x + ( beyond.xmin - xMin );
    }

    if ( yMax > beyond.ymax ) {
      y = y - ( yMax - beyond.ymax );
    } else if ( yMin < beyond.ymin ) {
      y = y + ( beyond.ymin - yMin );
    }

    newCoordiante = [[
      [p0[0] + x, p0[1] + y],
      [p1[0] + x, p1[1] + y],
      [p2[0] + x, p2[1] + y],
      [p3[0] + x, p3[1] + y],
      [p4[0] + x, p4[1] + y],
    ]];

    this.setCoordinates(newCoordiante)
  }

  static getLineCoordY (k, a, b, x) {
    const y = k * (x - a) + b; // 直线方程
    return y;
  }

  static getRefLineCoords(firstPoint, mousePoint) {
    const x1 = firstPoint[0];
    const x2 = mousePoint[0];
    const y1 = firstPoint[1];
    const y2 = mousePoint[1];

    if(firstPoint && mousePoint) {
      const _k = (y2 - y1) / (x2 - x1);
      const k = -1 / _k;

      let l1, l2;
      if(k === -Infinity) {
        l1 = [[x1, y1 - 300], [x1, y1 + 300]];
        l2 = [[x2, y2 - 300], [x2, y2 + 300]];
      } else {
        l1 = [[x1 - 300, this.getLineCoordY(k, x1, y1, x1 - 300)], [x1 + 300, this.getLineCoordY(k, x1, y1, x1 + 300)]];
        l2 = [[x2 - 300, this.getLineCoordY(k, x2, y2, x2 - 300)], [x2 + 300, this.getLineCoordY(k, x2, y2, x2 + 300)]];
      }
      return[l1, l2]
    }
  }

  rotate(extent, mouseDownX, mouseDownY, mouseMoveX, mouseMoveY) {
    var arr = this.getCoordinates()[0];

    //四个顶点坐标(x1,y1),(x2,y2),(x3,y3),(x4,y4)
    var x1 = arr[0][0],
      y1 = arr[0][1];
    var x2 = arr[1][0],
      y2 = arr[1][1];
    var x3 = arr[2][0],
      y3 = arr[2][1];
    var x4 = arr[3][0],
      y4 = arr[3][1];
    //矩形中心点(cX,cY)
    //利用两条相交线进行求解
    var k1 = (y3 - y1) / (x3 - x1);
    var k2 = (y4 - y2) / (x4 - x2);
    var cX = (y1 - k1 * x1 + k2 * x2 - y2) / (k2 - k1);
    var cY = k1 * cX + y1 - k1 * x1;
    //鼠标第一个点(mX1,mY1)
    var mX1 = mouseDownX;
    var mY1 = mouseDownY;
    //鼠标移动点(mX2,mY2)
    var mX2 = mouseMoveX;
    var mY2 = mouseMoveY;
    //旋转角度cos(θ) = cos;sin(θ) = sin;
    //通过向量的点积进行求解
    var abx = cX - mX1;
    var aby = cY - mY1;
    var acx = cX - mX2;
    var acy = cY - mY2;
    //叉乘求sin(θ)
    var abxac = abx * acy - acx * aby;
    var model =
      Math.sqrt(abx * abx + aby * aby) * Math.sqrt(acx * acx + acy * acy);
    var sin = abxac / model;
    //点乘求cos(θ)
    var abac = abx * acx + aby * acy;
    var cos = abac / model;
    //求旋转后的四个点(x11,y11),(x22,y22),(x33,y33),(x44,y44),(x55,y55)
    var x11 = (x1 - cX) * cos - (y1 - cY) * sin + cX;
    var y11 = (x1 - cX) * sin + (y1 - cY) * cos + cY;
  
    var x22 = (x2 - cX) * cos - (y2 - cY) * sin + cX;
    var y22 = (x2 - cX) * sin + (y2 - cY) * cos + cY;
  
    var x33 = (x3 - cX) * cos - (y3 - cY) * sin + cX;
    var y33 = (x3 - cX) * sin + (y3 - cY) * cos + cY;
  
    var x44 = (x4 - cX) * cos - (y4 - cY) * sin + cX;
    var y44 = (x4 - cX) * sin + (y4 - cY) * cos + cY;
  
    var x55 = x11;
    var y55 = y11;
    var arr = [[x11, y11], [x22, y22], [x33, y33], [x44, y44], [x55, y55]];
    //this.rotateData.mousedownX = mouseMoveX;
    //this.rotateData.mousedownY = mouseMoveY;
    if (extent) {
      var maxX = extent[2];
      var maxY = extent[3];
      if (
        x11 < 0 ||
        y11 < 0 ||
        x22 < 0 ||
        y22 < 0 ||
        x33 < 0 ||
        y33 < 0 ||
        x44 < 0 ||
        y44 < 0 ||
        x11 > maxX ||
        y11 > maxY ||
        x22 > maxX ||
        y22 > maxY ||
        x33 > maxX ||
        y33 > maxY ||
        x44 > maxX ||
        y44 > maxY
      ) {
        return;
      }
    }

    this.getCoordinates()[0] = arr;
  }

  getCoordinateIndex(coord) {
    return this.getCoordinates()[0].findIndex(points =>
      points[0] === coord[0] && points[1] === coord[1]
    )
  }

  clone() {
    return new TiltRectangle(this.getCoordinates())
  }

  /**
   * 根据得到的坐标点，计算出表单显示的位置
   *
   * @param {Number} offsetX x的偏移量
   * @param {Number} offsetY y的偏移量
   * @returns {[*,*]}
   */
  getFormShowPosition (offsetX = 0, offsetY = 0) {
    let rings = this.rings;
    let max = 0;
    let maxIndex = 0;
    rings[0].forEach((xy, index) => {
      if (xy[0] > max) {
        maxIndex = index;
        max = xy[0];
      }
    })
    return rings[0][maxIndex]
  }

  /**
   * 计算第三个坐标点
   * @param {*} coordinates 
   */
  static getThethreePoint(coordinates) {
    const firstPoint = coordinates[0]
    const secondPoint = coordinates[1]
    const thirdPoint = coordinates[2]
    const x1 = firstPoint[0]
    const y1 = firstPoint[1]
    const x2 = secondPoint[0]
    const y2 = secondPoint[1]
    const x3 = thirdPoint[0]
    const y3 = thirdPoint[1]
    if ( y2 - y1 === 0 ){
      return [x2, y3];
    } else if ( x2 - x1 === 0 ) {
      return [x3, y2];
    }
    const k1 = (y2 - y1) / (x2 - x1)
    const k2 = -(1 / k1)
    const x4 = (k1 * x3 - k2 * x2 + y2 - y3) / (k1 - k2)
    const y4 = (x4 - x3) * k1 + y3

    /*
    if (isNaN(x4)) {
      return [x3, y2]
    }*/
    return [x4, y4]
  }

  /**
   *
   * @param coordinates
   * @returns {Array}
   */
  static getTheLastPoint(coordinates, extent) {
    const arr = this.boundaryDetection(coordinates, extent)
    return arr
    // const flag = thirdPoint[0]>=0&&
    // thirdPoint[0]<maxX&&
    // thirdPoint[1]>=0&&
    // thirdPoint[1]<maxY&&
    // forthPoint[0]>=0&&
    // forthPoint[0]<maxX&&
    // forthPoint[1]>=0&&
    // forthPoint[1]<maxY
    // ?true:false
    // if(flag){
    //   this._thirdRecordPoint = thirdPoint
    //   this._forthRecordPoint = forthPoint
    //   return [firstPoint,secondPoint,this._thirdRecordPoint,this._forthRecordPoint,firstPoint]
    // }


  }
  static boundaryDetection(coordinates, extent) {
    const boundary = extent
    const coordinate = coordinates
    const firstPoint = coordinate[0]
    const secondPoint = coordinate[1]
    const thirdPoint = coordinate[2]

    let dx = thirdPoint[0] - secondPoint[0]
    let dy = thirdPoint[1] - secondPoint[1]
    const forthPoint = [firstPoint[0] + dx, firstPoint[1] + dy]
    let x1 = firstPoint[0]
    let y1 = firstPoint[1]
    let x2 = secondPoint[0]
    let y2 = secondPoint[1]
    let x3 = thirdPoint[0]
    let y3 = thirdPoint[1]
    let x4 = forthPoint[0]
    let y4 = forthPoint[1]
    if (!boundary) {
      return [[x1, y1], [x2, y2], [x3, y3], [x4, y4], [x1, y1]]
    }

    //边界检测判断
    const maxX = boundary[2]
    const maxY = boundary[3]


    let temp1X = 0
    let temp1Y = 0
    let temp2X = 0
    let temp2Y = 0
    let temp3X = 0
    let temp4X = 0
    let temp3Y = 0
    let temp4Y = 0
    if (x1 <= 0) {
      x1 = 0.0000000002
    }
    if (x1 >= maxX) {
      x1 = maxX - 0.000000002
    }
    if (y1 <= 0) {
      y1 = 0.0000000002
    }
    if (y1 >= maxY) {
      y1 = maxY - 0.000000002
    }
    if (x2 <= 0) {
      x2 = 0.00000000002
    }
    if (x2 >= maxX) {
      x2 = maxX - 0.00000000002
    }
    if (y2 <= 0) {
      y2 = 0.00000000002
    }
    if (y2 >= maxY) {
      y2 = maxY - 0.0000000002
    }


    if (x3 < 0) {
      temp3X = 0.0000000001
      temp3Y = y2 - (x2 - x1) * (temp3X - x2) / (y2 - y1)
      dx = temp3X - x2
      dy = temp3Y - y2
      temp4X = x1 + dx
      temp4Y = y1 + dy
      if (temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY && temp3Y >= 0 && temp3Y < maxY) {
        x4 = temp4X
        y4 = temp4Y
        y3 = temp3Y
        x3 = temp3X
      }
    }
    if (x3 > maxX) {
      temp3X = maxX - 0.0000000001
      temp3Y = y2 - (x2 - x1) * (temp3X - x2) / (y2 - y1)
      dx = temp3X - x2
      dy = temp3Y - y2
      temp4X = x1 + dx
      temp4Y = y1 + dy
      if (temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY && temp3Y >= 0 && temp3Y < maxY) {
        x4 = temp4X
        y4 = temp4Y
        y3 = temp3Y
        x3 = temp3X
      }
    }
    if (y3 < 0) {
      temp3Y = 0.0000000001
      temp3X = x2 - (y2 - y1) * (temp3Y - y2) / (x2 - x1)
      dx = temp3X - x2
      dy = temp3Y - y2
      temp4X = x1 + dx
      temp4Y = y1 + dy
      if (temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY && temp3X >= 0 && temp3X < maxX) {
        x4 = temp4X
        y4 = temp4Y
        x3 = temp3X
        y3 = temp3Y
      }
    }
    if (y3 > maxY) {
      temp3Y = maxY - 0.0000000001
      temp3X = x2 - (y2 - y1) * (temp3Y - y2) / (x2 - x1)
      dx = temp3X - x2
      dy = temp3Y - y2
      temp4X = x1 + dx
      temp4Y = y1 + dy
      if (temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY && temp3X >= 0 && temp3X < maxX) {
        x4 = temp4X
        y4 = temp4Y
        x3 = temp3X
        y3 = temp3Y
      }
    }
    if (x4 < 0) {
      temp4X = 0.00000000001
      temp4Y = y1 - (x2 - x1) * (temp4X - x1) / (y2 - y1)
      dx = temp4X - x1
      dy = temp4Y - y1
      temp3X = x2 + dx
      temp3Y = y2 + dy
      if (temp4Y >= 0 && temp4Y < maxY && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
        x3 = temp3X
        y3 = temp3Y
        y4 = temp4Y
        x4 = temp4X
      }
    }
    if (x4 > maxX) {
      temp4X = maxX - 0.00000000001
      temp4Y = y1 - (x2 - x1) * (temp4X - x1) / (y2 - y1)
      dx = temp4X - x1
      dy = temp4Y - y1
      temp3X = x2 + dx
      temp3Y = y2 + dy
      if (temp4Y >= 0 && temp4Y < maxY && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
        x3 = temp3X
        y3 = temp3Y
        y4 = temp4Y
        x4 = temp4X
      }
    }
    if (y4 < 0) {
      temp4Y = 0.00000000001
      temp4X = x1 - (y2 - y1) * (temp4Y - y1) / (x2 - x1)
      dx = temp4X - x1
      dy = temp4Y - y1
      temp3X = x2 + dx
      temp3Y = y2 + dy
      if (temp4X >= 0 && temp4X < maxX && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
        x3 = temp3X
        y3 = temp3Y
        x4 = temp4X
        y4 = temp4Y
      }
    }
    if (y4 > maxY) {
      temp4Y = maxY - 0.00000000001
      temp4X = x1 - (y2 - y1) * (temp4Y - y1) / (x2 - x1)
      dx = temp4X - x1
      dy = temp4Y - y1
      temp3X = x2 + dx
      temp3Y = y2 + dy
      if (temp4X >= 0 && temp4X < maxX && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
        x3 = temp3X
        y3 = temp3Y
        x4 = temp4X
        y4 = temp4Y
      }
    }
    return [[x1, y1], [x2, y2], [x3, y3], [x4, y4], [x1, y1]]
  }



  /**
   * 用于计算和更新平行四边形的顶点
   *
   * @param p 平行四边形对象
   * @param vertex 新移动的点
   * @param oldVertex 上次移动的点
   * @param dragSegment 数据对象
   * @returns {*} 返回新的点集合（3维数组）
   */
  static updateCoordinatesForModification(p, vertex, oldVertex, dragSegment, extent) {
    const boundary = extent
    let dis = 0
    if (oldVertex) {
      dis = distance(oldVertex, vertex)
    }

    const oldRingsCoordinates = p.getCoordinates()
    if (dis === 0) {
      return oldRingsCoordinates
    }

    const oldCoordinates = oldRingsCoordinates[0]
    const clonedCoordinates = deepClone(oldCoordinates)
    const revers = JSON.parse(JSON.stringify(oldRingsCoordinates[0]))
    const segement = dragSegment[0]
    const edgeIndex = segement.index
    const isVertex = segement.isVertex

    let firstCoord
    let nowCood
    let otherCood
    let secondCoord

    let firstVertex
    let secondVertex
    let thirdVertex
    let currentVertex

    // if (false) {
    //   if (edgeIndex === 0 || edgeIndex === 4) {
    //     firstVertex = oldCoordinates[3]
    //     secondVertex = oldCoordinates[2]
    //     currentVertex = oldCoordinates[0]
    //     thirdVertex = oldCoordinates[1]
    //   } else if (edgeIndex === 1) {
    //     firstVertex = oldCoordinates[0]
    //     secondVertex = oldCoordinates[3]
    //     currentVertex = oldCoordinates[1]
    //     thirdVertex = oldCoordinates[2]
    //   } else {
    //     firstVertex = oldCoordinates[edgeIndex - 1]
    //     secondVertex = oldCoordinates[edgeIndex - 2]
    //     currentVertex = oldCoordinates[edgeIndex]
    //     thirdVertex = oldCoordinates[edgeIndex + 1]
    //   }

    //   let x1 = firstVertex[0]
    //   let y1 = firstVertex[1]
    //   let x2 = secondVertex[0]
    //   let y2 = secondVertex[1]
    //   let x3 = thirdVertex[0]
    //   let y3 = thirdVertex[1]
    //   let x4 = vertex[0]
    //   let y4 = vertex[1]
    //   const k1 = (y1 - y2) / (x1 - x2)
    //   const k2 = -(1 / k1)
    //   const k3 = (y3 - y2) / (x3 - x2)
    //   const k4 = -(1 / k3)
    //   const newCood2X = (k2 * x4 - k1 * x1 + y1 - y4) / (k2 - k1)
    //   const newCood2Y = (newCood2X - x1) * k1 + y1
    //   const newCood3X = (k3 * x3 - k4 * x4 + y4 - y3) / (k3 - k4)
    //   const newCood3Y = (newCood3X - x3) * k3 + y3


    //   let newCood1, newCood2, newCood3
    //   newCood1 = vertex
    //   newCood2 = [newCood2X, newCood2Y]
    //   newCood3 = [newCood3X, newCood3Y]

    //   oldCoordinates[edgeIndex] = newCood1
    //   oldCoordinates[edgeIndex + 1] = newCood2
    //   oldCoordinates[edgeIndex - 1] = newCood3

    //   if (edgeIndex === 0 || edgeIndex === 4) {
    //     firstCoord = oldCoordinates[3] = newCood2
    //     oldCoordinates[0] = newCood1
    //     oldCoordinates[1] = newCood3
    //   } else if (edgeIndex === 1) {
    //     oldCoordinates[0] = newCood2
    //     oldCoordinates[1] = newCood1
    //     oldCoordinates[2] = newCood3
    //   } else {
    //     oldCoordinates[edgeIndex - 1] = newCood2
    //     oldCoordinates[edgeIndex] = newCood1
    //     oldCoordinates[edgeIndex + 1] = newCood3
    //   }
    // }
    if (edgeIndex === 0 || edgeIndex === 4) {
      firstCoord = oldCoordinates[3]
      secondCoord = oldCoordinates[2]
      nowCood = oldCoordinates[0]
      otherCood = oldCoordinates[1]
    } else if (edgeIndex === 1) {
      firstCoord = oldCoordinates[0]
      secondCoord = oldCoordinates[3]
      nowCood = oldCoordinates[1]
      otherCood = oldCoordinates[2]
    } else {
      firstCoord = oldCoordinates[edgeIndex - 1]
      secondCoord = oldCoordinates[edgeIndex - 2]
      nowCood = oldCoordinates[edgeIndex]
      otherCood = oldCoordinates[edgeIndex + 1]
    }
    // if (edgeIndex === 0 || edgeIndex === 4) {
    //   firstVertex = oldCoordinates[3]
    //   secondVertex = oldCoordinates[2]
    //   nowCood = oldCoordinates[0]
    //   thirdVertex = oldCoordinates[1]
    // } else if (edgeIndex === 1) {
    //   firstVertex = oldCoordinates[0]
    //   secondVertex = oldCoordinates[3]
    //   nowCood = oldCoordinates[1]
    //   thirdVertex = oldCoordinates[2]
    // } else {
    //   firstVertex = oldCoordinates[edgeIndex - 1]
    //   secondVertex = oldCoordinates[edgeIndex - 2]
    //   nowCood = oldCoordinates[edgeIndex]
    //   thirdVertex = oldCoordinates[edgeIndex + 1]
    // }
    // 计算延长线上的一点,并做边界检测
    const newCood1 = getPointInExtendedLineByDistanceFromABOrC(firstCoord[0],
      firstCoord[1], nowCood[0], nowCood[1], secondCoord[0], secondCoord[1], dis)
    // if (!newCood1[0]||!newCood1[1]) {
    //   return oldRingsCoordinates
    // }
    // 计算向量
    const tempXX = nowCood[0] - firstCoord[0]
    const tempYY = nowCood[1] - firstCoord[1]
    const tempX2 = vertex[0] - oldVertex[0]
    const tempY2 = vertex[1] - oldVertex[1]

    // 使用向量的点积，来计算两个向量的方向是否一致
    // 如果 <0 则表示异向
    const direction = (tempX2 * tempXX) + (tempY2 * tempYY)

    const dxx = newCood1[0] - nowCood[0]
    const dyy = newCood1[1] - nowCood[1]
    let newCood2
    let exceed = false//判断是否反方向拉伸了
    // 不同方向
    if (direction < 0) {
      newCood1[0] = nowCood[0] - dxx
      newCood1[1] = nowCood[1] - dyy

      newCood2 = [otherCood[0] - dxx, otherCood[1] - dyy]
      //矩形的坐标移动的长度是否超过原本长度
      let originDist = Math.sqrt((nowCood[0] - firstCoord[0]) * (nowCood[0] - firstCoord[0]) + (nowCood[1] - firstCoord[1]) * (nowCood[1] - firstCoord[1]))
      let nowDist = Math.sqrt((newCood1[0] - firstCoord[0]) * (newCood1[0] - firstCoord[0]) + (newCood1[1] - firstCoord[1]) * (newCood1[1] - firstCoord[1]))
      if (nowDist > originDist) {
        exceed = false
      } else {
        exceed = true
      }
    } else {
      newCood2 = [otherCood[0] + dxx, otherCood[1] + dyy]
      exceed = true
    }
    //矩形的最小宽度
    let distan = Math.sqrt((newCood1[0] - firstCoord[0]) * (newCood1[0] - firstCoord[0]) + (newCood1[1] - firstCoord[1]) * (newCood1[1] - firstCoord[1]))

    //if (distan > 10 && exceed) {
    if (exceed) {
      oldCoordinates[edgeIndex] = newCood1
      oldCoordinates[edgeIndex + 1] = newCood2
      if (edgeIndex === 0) {
        oldCoordinates[4] = oldCoordinates[0]
      } else if (edgeIndex === 4 || edgeIndex === 3) {
        oldCoordinates[0] = oldCoordinates[4]
      }
    }

    if (!boundary) {
      return [oldCoordinates];
    }

    //边界检测判断
    const maxX = boundary[2]
    const maxY = boundary[3]
    let x1 = oldCoordinates[0][0]
    let y1 = oldCoordinates[0][1]
    let x2 = oldCoordinates[1][0]
    let y2 = oldCoordinates[1][1]
    let x3 = oldCoordinates[2][0]
    let y3 = oldCoordinates[2][1]
    let x4 = oldCoordinates[3][0]
    let y4 = oldCoordinates[3][1]
    let temp1X = 0
    let temp1Y = 0
    let temp2X = 0
    let temp2Y = 0
    let temp3X = 0
    let temp4X = 0
    let temp3Y = 0
    let temp4Y = 0
    let dx = 0
    let dy = 0
    //判断拉的是1-2边，判断(x1,y1) (x2,y2)
    if (edgeIndex == 0) {
      //判断(x1,y1)
      if (x1 < 0) {
        temp1X = 0.000000001
        if (y4 == y3) {
          temp1Y = y4
        } else {
          temp1Y = y4 - (x4 - x3) * (temp1X - x4) / (y4 - y3)
        }

        dx = temp1X - x4
        dy = temp1Y - y4
        temp2X = x3 + dx
        temp2Y = y3 + dy
        if (temp2X >= 0 && temp2X < maxX && temp2Y >= 0 && temp2Y < maxY && temp1Y >= 0 && temp1Y < maxY) {
          x1 = temp1X
          y1 = temp1Y
          x2 = temp2X
          y2 = temp2Y
        }
      }
      if (x1 > maxX) {
        temp1X = maxX - 0.0000001
        if (y4 == y3) {
          temp1Y = y4
        } else {
          temp1Y = y4 - (x4 - x3) * (temp1X - x4) / (y4 - y3)
        }
        dx = temp1X - x4
        dy = temp1Y - y4
        temp2X = x3 + dx
        temp2Y = y3 + dy
        if (temp2X >= 0 && temp2X < maxX && temp2Y >= 0 && temp2Y < maxY && temp1Y >= 0 && temp1Y < maxY) {
          x1 = temp1X
          y1 = temp1Y
          x2 = temp2X
          y2 = temp2Y
        }
      }
      if (y1 < 0) {
        temp1Y = 0.000000001
        if (x4 == x3) {
          temp1X = x4
        } else {
          temp1X = x4 - (y4 - y3) * (temp1Y - y4) / (x4 - x3)
        }
        dx = temp1X - x4
        dy = temp1Y - y4
        temp2X = x3 + dx
        temp2Y = y3 + dy
        if (temp2X >= 0 && temp2X < maxX && temp2Y >= 0 && temp2Y < maxY && temp1Y >= 0 && temp1Y < maxY) {
          x1 = temp1X
          y1 = temp1Y
          x2 = temp2X
          y2 = temp2Y
        }
      }
      if (y1 > maxY) {
        temp1Y = maxY - 0.0000001
        if (x4 == x3) {
          temp1X = x4
        } else {
          temp1X = x4 - (y4 - y3) * (temp1Y - y4) / (x4 - x3)

        }
        dx = temp1X - x4
        dy = temp1Y - y4
        temp2X = x3 + dx
        temp2Y = y3 + dy
        if (temp2X >= 0 && temp2X < maxX && temp2Y >= 0 && temp2Y < maxY && temp1Y >= 0 && temp1Y < maxY) {
          x1 = temp1X
          y1 = temp1Y
          x2 = temp2X
          y2 = temp2Y
        }
      }
      //判断(x1,y2)
      if (x2 < 0) {
        temp2X = 0.0000000001
        if (y4 == y3) {
          temp2Y = y3
        } else {
          temp2Y = y3 - (x4 - x3) * (temp2X - x3) / (y4 - y3)

        }
        dx = temp2X - x3
        dy = temp2Y - y3
        temp1X = x4 + dx
        temp1Y = y4 + dy
        if (temp2Y >= 0 && temp2Y < maxY && temp1X >= 0 && temp1X < maxX && temp1Y >= 0 && temp1Y < maxY) {
          x1 = temp1X
          y1 = temp1Y
          x2 = temp2X
          y2 = temp2Y
        }
      }
      if (x2 > maxX) {
        temp2X = maxX - 0.00000001
        if (y4 == y3) {
          temp2Y = y3
        } else {
          temp2Y = y3 - (x4 - x3) * (temp2X - x3) / (y4 - y3)

        }
        dx = temp2X - x3
        dy = temp2Y - y3
        temp1X = x4 + dx
        temp1Y = y4 + dy
        if (temp2Y >= 0 && temp2Y < maxY && temp1X >= 0 && temp1X < maxX && temp1Y >= 0 && temp1Y < maxY) {
          x1 = temp1X
          y1 = temp1Y
          x2 = temp2X
          y2 = temp2Y
        }
      }
      if (y2 < 0) {
        temp2Y = 0.0000000001
        if (x4 == x3) {
          temp2X = x3
        } else {
          temp2X = x3 - (y4 - y3) * (temp2Y - y3) / (x4 - x3)

        }
        dx = temp2X - x3
        dy = temp2Y - y3
        temp1X = x4 + dx
        temp1Y = y4 + dy
        if (temp2X >= 0 && temp2X < maxX && temp1X >= 0 && temp1X < maxX && temp1Y >= 0 && temp1Y < maxY) {
          x1 = temp1X
          y1 = temp1Y
          x2 = temp2X
          y2 = temp2Y
        }
      }
      if (y2 > maxY) {
        temp2Y = maxY - 0.00000001
        if (x4 == x3) {
          temp2X = x3
        } else {
          temp2X = x3 - (y4 - y3) * (temp2Y - y3) / (x4 - x3)

        }
        dx = temp2X - x3
        dy = temp2Y - y3
        temp1X = x4 + dx
        temp1Y = y4 + dy
        if (temp2X >= 0 && temp2X < maxX && temp1X >= 0 && temp1X < maxX && temp1Y >= 0 && temp1Y < maxY) {
          x1 = temp1X
          y1 = temp1Y
          x2 = temp2X
          y2 = temp2Y
        }
      }
    }
    //判断(x2,y2),(x3,y3)
    if (edgeIndex == 1) {
      //判断(x2,y2)
      if (x2 < 0) {
        temp2X = 0.00000000001
        if (y4 == y1) {
          temp2Y = y1
        } else {
          temp2Y = y1 - (temp2X - x1) * (x4 - x1) / (y4 - y1)

        }
        dx = temp2X - x1
        dy = temp2Y - y1
        temp3X = x4 + dx
        temp3Y = y4 + dy
        if (temp2Y >= 0 && temp2Y < maxY && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
          x2 = temp2X
          y2 = temp2Y
          x3 = temp3X
          y3 = temp3Y
        }
      }
      if (x2 > maxX) {
        temp2X = maxX - 0.0000000001
        if (y4 == y1) {
          temp2Y = y1
        } else {
          temp2Y = y1 - (temp2X - x1) * (x4 - x1) / (y4 - y1)

        }
        dx = temp2X - x1
        dy = temp2Y - y1
        temp3X = x4 + dx
        temp3Y = y4 + dy
        if (temp2Y >= 0 && temp2Y < maxY && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
          x2 = temp2X
          y2 = temp2Y
          x3 = temp3X
          y3 = temp3Y
        }
      }
      if (y2 < 0) {
        temp2Y = 0.00000000001
        if (x4 == x1) {
          temp2X = x1
        } else {
          temp2X = x1 - (temp2Y - y1) * (y4 - y1) / (x4 - x1)

        }
        dx = temp2X - x1
        dy = temp2Y - y1
        temp3X = x4 + dx
        temp3Y = y4 + dy
        if (temp2X >= 0 && temp2X < maxX && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
          x2 = temp2X
          y2 = temp2Y
          x3 = temp3X
          y3 = temp3Y
        }
      }
      if (y2 > maxY) {
        temp2Y = maxY - 0.000000001
        if (x4 == x1) {
          temp2X = x1
        } else {
          temp2X = x1 - (temp2Y - y1) * (y4 - y1) / (x4 - x1)

        }
        dx = temp2X - x1
        dy = temp2Y - y1
        temp3X = x4 + dx
        temp3Y = y4 + dy
        if (temp2X >= 0 && temp2X < maxX && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
          x2 = temp2X
          y2 = temp2Y
          x3 = temp3X
          y3 = temp3Y
        }
      }
      //判断(x3,y3)
      if (x3 < 0) {
        temp3X = 0.000000000001
        if (y4 == y1) {
          temp3Y = y4
        } else {
          temp3Y = y4 - (temp3X - x4) * (x4 - x1) / (y4 - y1)

        }
        dx = temp3X - x4
        dy = temp3Y - y4
        temp2X = x1 + dx
        temp2Y = y1 + dy
        if (temp3Y >= 0 && temp3Y < maxY && temp2X >= 0 && temp2X < maxX && temp2Y >= 0 && temp2Y < maxY) {
          x2 = temp2X
          y2 = temp2Y
          x3 = temp3X
          y3 = temp3Y
        }
      }
      if (x3 > maxX) {
        temp3X = maxX - 0.00000000001
        if (y4 == y1) {
          temp3Y = y4
        } else {
          temp3Y = y4 - (temp3X - x4) * (x4 - x1) / (y4 - y1)

        }
        dx = temp3X - x4
        dy = temp3Y - y4
        temp2X = x1 + dx
        temp2Y = y1 + dy
        if (temp3Y >= 0 && temp3Y < maxY && temp2X >= 0 && temp2X < maxX && temp2Y >= 0 && temp2Y < maxY) {
          x2 = temp2X
          y2 = temp2Y
          x3 = temp3X
          y3 = temp3Y
        }
      }
      if (y3 < 0) {
        temp3Y = 0.000000000001
        if (x4 == x1) {
          temp3X = x4
        } else {
          temp3X = x4 - (temp3Y - y4) * (y4 - y1) / (x4 - x1)

        }
        dx = temp3X - x4
        dy = temp3Y - y4
        temp2X = x1 + dx
        temp2Y = y1 + dy
        if (temp3X >= 0 && temp3X < maxX && temp2X >= 0 && temp2X < maxX && temp2Y >= 0 && temp2Y < maxY) {
          x2 = temp2X
          y2 = temp2Y
          x3 = temp3X
          y3 = temp3Y
        }
      }
      if (y3 > maxY) {
        temp3Y = maxY - 0.0000000001
        if (x4 == x1) {
          temp3X = x4
        } else {
          temp3X = x4 - (temp3Y - y4) * (y4 - y1) / (x4 - x1)

        }
        dx = temp3X - x4
        dy = temp3Y - y4
        temp2X = x1 + dx
        temp2Y = y1 + dy
        if (temp3X >= 0 && temp3X < maxX && temp2X >= 0 && temp2X < maxX && temp2Y >= 0 && temp2Y < maxY) {
          x2 = temp2X
          y2 = temp2Y
          x3 = temp3X
          y3 = temp3Y
        }
      }
    }
    //判断(x3,y3)(x4,y4)
    if (edgeIndex == 2) {
      //判断(x3,y3)
      if (x3 < 0) {
        temp3X = 0.0000000000001
        if (y2 == y1) {
          temp3Y = y2
        } else {
          temp3Y = y2 - (temp3X - x2) * (x2 - x1) / (y2 - y1)

        }
        dx = temp3X - x2
        dy = temp3Y - y2
        temp4X = x1 + dx
        temp4Y = y1 + dy
        if (temp3Y >= 0 && temp3Y < maxY && temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY) {
          x3 = temp3X
          y3 = temp3Y
          x4 = temp4X
          y4 = temp4Y
        }
      }
      if (x3 > maxX) {
        temp3X = maxX - 0.000000000001
        if (y2 == y1) {
          temp3Y = y2
        } else {
          temp3Y = y2 - (temp3X - x2) * (x2 - x1) / (y2 - y1)

        }
        dx = temp3X - x2
        dy = temp3Y - y2
        temp4X = x1 + dx
        temp4Y = y1 + dy
        if (temp3Y >= 0 && temp3Y < maxY && temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY) {
          x3 = temp3X
          y3 = temp3Y
          x4 = temp4X
          y4 = temp4Y
        }
      }
      if (y3 < 0) {
        temp3Y = 0.0000000000001
        if (x2 == x1) {
          temp3X = x2
        } else {
          temp3X = x2 - (temp3Y - y2) * (y2 - y1) / (x2 - x1)

        }
        dx = temp3X - x2
        dy = temp3Y - y2
        temp4X = x1 + dx
        temp4Y = y1 + dy
        if (temp3X >= 0 && temp3X < maxX && temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY) {
          x3 = temp3X
          y3 = temp3Y
          x4 = temp4X
          y4 = temp4Y
        }
      }
      if (y3 > maxY) {
        temp3Y = maxY - 0.00000000001
        if (x2 == x1) {
          temp3X = x2
        } else {
          temp3X = x2 - (temp3Y - y2) * (y2 - y1) / (x2 - x1)

        }
        dx = temp3X - x2
        dy = temp3Y - y2
        temp4X = x1 + dx
        temp4Y = y1 + dy
        if (temp3X >= 0 && temp3X < maxX && temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY) {
          x3 = temp3X
          y3 = temp3Y
          x4 = temp4X
          y4 = temp4Y
        }
      }
      //判断(x4,y4)
      if (x4 < 0) {
        temp4X = 0.00000000000001
        if (y2 == y1) {
          temp4Y = y1
        } else {
          temp4Y = y1 - (temp4X - x1) * (x2 - x1) / (y2 - y1)

        }
        dx = temp4X - x1
        dy = temp4Y - y1
        temp3X = x2 + dx
        temp3Y = y2 + dy
        if (temp4Y >= 0 && temp4Y < maxY && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
          x3 = temp3X
          y3 = temp3Y
          x4 = temp4X
          y4 = temp4Y
        }
      }
      if (x4 > maxX) {
        temp4X = maxX - 0.0000000000001
        if (y2 == y1) {
          temp4Y = y1
        } else {
          temp4Y = y1 - (temp4X - x1) * (x2 - x1) / (y2 - y1)

        }
        dx = temp4X - x1
        dy = temp4Y - y1
        temp3X = x2 + dx
        temp3Y = y2 + dy
        if (temp4Y >= 0 && temp4Y < maxY && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
          x3 = temp3X
          y3 = temp3Y
          x4 = temp4X
          y4 = temp4Y
        }
      }
      if (y4 < 0) {
        temp4Y = 0.00000000000001
        if (x2 == x1) {
          temp4X = x1
        } else {
          temp4X = x1 - (temp4Y - y1) * (y2 - y1) / (x2 - x1)

        }
        dx = temp4X - x1
        dy = temp4Y - y1
        temp3X = x2 + dx
        temp3Y = y2 + dy
        if (temp4X >= 0 && temp4X < maxX && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
          x3 = temp3X
          y3 = temp3Y
          x4 = temp4X
          y4 = temp4Y
        }
      }
      if (y4 > maxY) {
        temp4Y = maxY - 0.000000000001
        if (x2 == x1) {
          temp4X = x1
        } else {
          temp4X = x1 - (temp4Y - y1) * (y2 - y1) / (x2 - x1)

        }
        dx = temp4X - x1
        dy = temp4Y - y1
        temp3X = x2 + dx
        temp3Y = y2 + dy
        if (temp4X >= 0 && temp4X < maxX && temp3X >= 0 && temp3X < maxX && temp3Y >= 0 && temp3Y < maxY) {
          x3 = temp3X
          y3 = temp3Y
          x4 = temp4X
          y4 = temp4Y
        }
      }
    }
    //判断(x4,y4)(x1,y1)
    if (edgeIndex == 3) {
      //判断(x4,y4)
      if (x4 < 0) {
        temp4X = 0.000000000000001
        // if (y3 == y1) {
        if (y3 == y2) {
          temp4Y = y3
        } else {
          temp4Y = y3 - (temp4X - x3) * (x3 - x2) / (y3 - y2)

        }
        dx = temp4X - x3
        dy = temp4Y - y3
        temp1X = x2 + dx
        temp1Y = y2 + dy
        if (temp4Y >= 0 && temp4Y < maxY && temp1X >= 0 && temp1X < maxX && temp1Y >= 0 && temp1Y < maxY) {
          x4 = temp4X
          y4 = temp4Y
          x1 = temp1X
          y1 = temp1Y
        }
      }
      if (x4 > maxX) {
        temp4X = maxX - 0.00000000000001
        if (y3 == y2) {
          temp4Y = y3
        } else {
          temp4Y = y3 - (temp4X - x3) * (x3 - x2) / (y3 - y2)

        }
        dx = temp4X - x3
        dy = temp4Y - y3
        temp1X = x2 + dx
        temp1Y = y2 + dy
        if (temp4Y >= 0 && temp4Y < maxY && temp1X >= 0 && temp1X < maxX && temp1Y >= 0 && temp1Y < maxY) {
          x4 = temp4X
          y4 = temp4Y
          x1 = temp1X
          y1 = temp1Y
        }
      }
      if (y4 < 0) {
        temp4Y = 0.000000000000001
        if (x3 == x2) {
          temp4X = x3
        } else {
          temp4X = x3 - (temp4Y - y3) * (y3 - y2) / (x3 - x2)

        }
        dx = temp4X - x3
        dy = temp4Y - y3
        temp1X = x2 + dx
        temp1Y = y2 + dy
        if (temp4X >= 0 && temp4X < maxX && temp1X >= 0 && temp1X < maxX && temp1Y >= 0 && temp1Y < maxY) {
          x4 = temp4X
          y4 = temp4Y
          x1 = temp1X
          y1 = temp1Y
        }
      }
      if (y4 > maxY) {
        temp4Y = maxY - 0.0000000000001
        if (x3 == x2) {
          temp4X = x3
        } else {
          temp4X = x3 - (temp4Y - y3) * (y3 - y2) / (x3 - x2)

        }
        dx = temp4X - x3
        dy = temp4Y - y3
        temp1X = x2 + dx
        temp1Y = y2 + dy
        if (temp4X >= 0 && temp4X < maxX && temp1X >= 0 && temp1X < maxX && temp1Y >= 0 && temp1Y < maxY) {
          x4 = temp4X
          y4 = temp4Y
          x1 = temp1X
          y1 = temp1Y
        }
      }
      //判断(x1,y1)
      if (x1 < 0) {
        temp1X = 0.0000000000000001
        if (y2 == y3) {
          temp1Y = y2
        } else {
          temp1Y = y2 - (temp1X - x2) * (x2 - x3) / (y2 - y3)

        }
        dx = temp1X - x2
        dy = temp1Y - y2
        temp4X = x3 + dx
        temp4Y = y3 + dy
        if (temp1Y >= 0 && temp1Y < maxX && temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY) {
          x4 = temp4X
          y4 = temp4Y
          x1 = temp1X
          y1 = temp1Y
        }
      }
      if (x1 > maxX) {
        temp1X = maxX - 0.000000000000001
        if (y2 == y3) {
          temp1Y = y2
        } else {
          temp1Y = y2 - (temp1X - x2) * (x2 - x3) / (y2 - y3)

        }
        dx = temp1X - x2
        dy = temp1Y - y2
        temp4X = x3 + dx
        temp4Y = y3 + dy
        if (temp1Y >= 0 && temp1Y < maxY && temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY) {
          x4 = temp4X
          y4 = temp4Y
          x1 = temp1X
          y1 = temp1Y
        }
      }
      if (y1 < 0) {
        temp1Y = 0.0000000000000001
        if (x2 == x3) {
          temp1X = x2
        } else {
          temp1X = x2 - (temp1Y - y2) * (y2 - y3) / (x2 - x3)

        }
        dx = temp1X - x2
        dy = temp1Y - y2
        temp4X = x3 + dx
        temp4Y = y3 + dy
        if (temp1X >= 0 && temp1X < maxX && temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY) {
          x4 = temp4X
          y4 = temp4Y
          x1 = temp1X
          y1 = temp1Y
        }
      }
      if (y1 > maxY) {
        temp1Y = maxY - 0.00000000000001
        if (x2 == x3) {
          temp1X = x2
        } else {
          temp1X = x2 - (temp1Y - y2) * (y2 - y3) / (x2 - x3)

        }
        dx = temp1X - x2
        dy = temp1Y - y2
        temp4X = x3 + dx
        temp4Y = y3 + dy
        if (temp1X >= 0 && temp1X < maxX && temp4X >= 0 && temp4X < maxX && temp4Y >= 0 && temp4Y < maxY) {
          x4 = temp4X
          y4 = temp4Y
          x1 = temp1X
          y1 = temp1Y
        }
      }
    }
    //判断当有两个相邻点同时x=0或者y=0 且是同一个坐标
    // if((x1==0&&x2==0&&y1==y2)||
    // (y1==0&&y2==0&&x1==x2)||
    // (x2==0&&x3==0&&y2==y3)||
    // (y2==0&&y3==0&&x2==x3)||
    // (x3==0&&x4==0&&y3==y4)||
    // (y3==0&&y4==0&&x3==x4)||
    // (x4==0&&x1==0&&y1==y4)||
    // (y1==0&&y4==0&&x1==x4)){

    // }
    oldCoordinates[0] = [x1, y1]
    oldCoordinates[1] = [x2, y2]
    oldCoordinates[2] = [x3, y3]
    oldCoordinates[3] = [x4, y4]
    oldCoordinates[4] = [x1, y1]
    //console.log(`x1:${x1},y1:${y1},x2:${x2},y2:${y2},x3:${x3},y3:${y3},x4:${x4},y4:${y4}`)
    if (isVertex) {
      if (edgeIndex == 0) {
        const p1 = getProjectionPointOnLine(clonedCoordinates[1], clonedCoordinates[2], vertex)
        const p2 = getProjectionPointOnLine(clonedCoordinates[2], clonedCoordinates[3], vertex)
        oldCoordinates[0] = vertex
        oldCoordinates[4] = vertex
        oldCoordinates[1] = p1
        oldCoordinates[3] = p2
      } else if (edgeIndex == 1) {
        const p1 = getProjectionPointOnLine(clonedCoordinates[0], clonedCoordinates[3], vertex)
        const p2 = getProjectionPointOnLine(clonedCoordinates[2], clonedCoordinates[3], vertex)
        oldCoordinates[0] = p1
        oldCoordinates[4] = p1
        oldCoordinates[2] = p2
        oldCoordinates[1] = vertex
      } else if (edgeIndex == 2) {
        const p1 = getProjectionPointOnLine(clonedCoordinates[0], clonedCoordinates[1], vertex)
        const p2 = getProjectionPointOnLine(clonedCoordinates[0], clonedCoordinates[3], vertex)
        oldCoordinates[1] = p1
        oldCoordinates[3] = p2
        oldCoordinates[2] = vertex
      } else if (edgeIndex == 3) {
        const p1 = getProjectionPointOnLine(clonedCoordinates[0], clonedCoordinates[1], vertex)
        const p2 = getProjectionPointOnLine(clonedCoordinates[1], clonedCoordinates[2], vertex)
        oldCoordinates[0] = p1
        oldCoordinates[4] = p1
        oldCoordinates[2] = p2
        oldCoordinates[3] = vertex
      }
    }
    if (p.fixedRate) {
      updateTiltRectByRatio(oldCoordinates, p.fixedRate, edgeIndex)
    }

    if (boundary) {
      const [xmin, ymin, xmax, ymax] = boundary
      const isBeyond = oldCoordinates.some(coord => {
        return coord[0] < xmin ||
          coord[1] < ymin ||
          coord[0] > xmax ||
          coord[1] > ymax
      });

      if (isBeyond) {
        return [clonedCoordinates]
      }
    }
    return [oldCoordinates]
  }


}
